package thread;

import javax.swing.*;
import java.awt.*;

class util {
    public static Image bg = Toolkit.getDefaultToolkit().getImage("D:\\idea\\bjtp\\sdbj2.jpg");
}

public class Test extends JFrame {
    public static void main(String[] args) {
        Test TuPian = new Test();
        TuPian.launch();
    }

    @Override
    public void paint(Graphics g) {
        g.drawImage(util.bg,0,0,null);
        g.setColor(Color.green);
        g.setFont(new Font("黑体",Font.BOLD,10));
//        g.drawString("圣",295,100);
//        g.drawString("圣诞快",285,115);
        String[] s = {"圣","诞","快","乐","！","圣","诞","快","乐","！","圣","诞","快","乐","！"
                ,"圣","诞","快","乐","！","圣","诞","快","乐","！","圣","诞","快","乐","！"
                ,"圣","诞","快","乐","！","圣","诞","快","乐","！","圣","诞","快","乐","！"
                ,"圣","诞","快","乐","！","圣","诞","快","乐","！","圣","诞","快","乐","！"};
        //第一块
        for (int i =110;i < 230;i += 15){
            for(int j = 0;j < (i-110)*2/15+1;j ++){
                g.drawString(s[j],295-(i-110)/3*2+10*j,i);
            }
        }
        //第二块
        for (int i =230;i<355;i+=15){
            for (int j = 0;j < (i-215)*2/15+3;j ++)
                g.drawString(s[j],275-(i-230)/3*2+10*j,i);
        }
        //第三块
        for (int i =365;i<560;i+=15){
            for (int j = 0;j < (i-365)*2/15+9;j ++)
                g.drawString(s[j],255-(i-365)/3*2+10*j,i);
        }
        g.setColor(new Color(230,120,0));
        for (int i =560;i<630;i+=15){
            g.drawString("圣诞快乐！",275,i);
        }
    }

    public void launch() {
//       设置窗口是否可见
        this.setVisible(true);
//        设置窗口大小
        this.setSize(600,700);
//        设置窗口位置
        this.setLocationRelativeTo(null);
//        设置窗口标题
        this.setTitle("圣诞树");
    }
}
